<div>
    <?php if (!isset($this->erros)): ?>
        <form id="<?= $this->form->getId() ?>" action="<?= $this->form->getAction() ?>" method="post">

            <? foreach ($this->form as $element): ?>
                <?= $element ?>
            <? endforeach ?>

            <div>
                <table class="table table-bordered table-striped" style="width: 400px;">
                    <thead>
                        <tr>
                            <th>Descrição</th>
                            <th style="text-align: center;">Edição <input type="checkbox" id="checkAllEd"/></th>
                            <th style="text-align: center;">Consulta<input type="checkbox" id="checkAllCon"/></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($this->modulos as $modulo): ?>
                            <?php
                                if (!isset($this->perfis) || count($this->perfis) == 0) {
                                    $edicao = '';
                                    $consulta = '';
                                }else{
                                    $edicao = '';
                                    $consulta = '';
                                    foreach ($this->perfis as $value) {
                                        if($value['modulo'] == $modulo['codigo']){
                                            if($value['edita']=='S'){
                                                $edicao='checked="checked"';
                                            }else{
                                                $edicao='';
                                            }
                                            if($value['consulta']=='S'){
                                                $consulta='checked="checked"';
                                            }else{
                                                $consulta='';
                                            }
                                        }
                                    }
                                }
                            ?>
                            <tr>
                                <td><?= $modulo['nome'] ?></td>
                                <td style="text-align: center;">
                                    <input type="checkbox" name="modulo_ed[]" class="checkAllEd" value="<?= $modulo['codigo'] ?>" <?= $edicao ?>/>
                                </td>
                                <td style="text-align: center;">
                                    <input type="checkbox" name="modulo_con[]" class="checkAllCon" value="<?= $modulo['codigo'] ?>" <?= $consulta ?>/>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>

            <input  type="submit" id="btnEnviar" value="Salvar" class="btn-large"/>
            <input  type="button" id="btnExcluir" value="Excluir" class="btn-large"/>
        </form>
    <?php else: ?>
        <a href="<?= $this->url(array('controller' => 'consulta', 'action' => 'index')) ?>"> Voltar</a>
    <?php endif; ?>
</div>


